
/*S 请求数据加密解密
 *  加密4各参数  需要加密的json字符串jsonStr, 制作key的字符串userid, 跳转url或请求urlLink 加密解密des
 *  解密三个参数 加密后的字符串，key和des
 *  urlLink、des的值为boolean
*/
function wb_des(jsonStr,userid,des){
    if(des){
         //des为true加密
        var jsons = JSON.stringify(jsonStr);
        var data = CryptoJS.enc.Utf8.parse(jsons);
        userid = userid+''
        //MD5加密并转大写截取16位
        if(userid == null || userid == "0"){
            userid = "";
        }
        var temp = userid+hex_md5(userid);
        // console.log('temp='+temp);
        var uid = hex_md5(temp.toUpperCase()).toUpperCase().substring(0,16);
        // console.log('uid='+uid);
        var key  = CryptoJS.enc.Utf8.parse(uid);
        // console.log('key='+key);
        //加密key和iv参数相同
        var  encrypted = CryptoJS.AES.encrypt(data,key,{iv:key,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.ZeroPadding});
        var data2 = {"data":encrypted.toString()};
        var key2 = {"UserID":userid,"wechat":"wechat"};
        return {"data":data2,"key":key2};
    }else{
        //des为false解密
        return CryptoJS.AES.decrypt(jsonStr,userid,{iv:userid,padding:CryptoJS.pad.ZeroPadding}).toString(CryptoJS.enc.Utf8);
    }
}
/*E 请求数据加密解密*/

